import instance from '@/utils/axios.js'

function getChannelList() {
    return instance({
        url: '/v1_0/channels',
        method: 'get'
    })
}
export { getChannelList }

function getArticleList({channel_id,timestamp }) {
    return instance({
        url: '/v1_0/articles',
        method: 'get',
        params: {
            with_top: 1,
            channel_id,
            timestamp
        }
    })
}
export { getArticleList }

function getArticleInfo(id) {
    return instance({
        url: `/v1_0/articles/${id}`,
        method: 'get'
    })
}
export { getArticleInfo }

function addFollowing(target) {
    return instance({
        url: '/v1_0/user/followings',
        method: 'post',
        data: {target}
    })
}

function removeFollowing(target) {
    return instance({
        url: `/v1_0/user/followings/${target}`,
        method: 'delete',
    })
}
export { addFollowing, removeFollowing }

function addLikings(target) {
    return instance({
        url: '/v1_0/article/likings',
        method: 'post',
        data: {target}
    })
}

function removeLikings(target) {
    return instance({
        url: `/v1_0/article/likings/${target}`,
        method: 'delete',
    })
}
export { addLikings, removeLikings }

function getSuggestion(q) {
    return instance({
        url: '/v1_0/suggestion',
        method: 'get',
        params: {q}
    })
}
export { getSuggestion }

function removeDisLikes(target) {
    return instance({
        url: `/v1_0/article/dislikes/${target}`,
        method: 'delete',
    })
}
export { removeDisLikes }

function addDisLikes(target) {
    return instance({
        url: '/v1_0/article/dislikes',
        method: 'post',
        data:{target}
    })
}
export { addDisLikes }

function getSearchList({page,q}) {
    return instance({
        url: '/v1_0/search',
        method: 'get',
        params: {
            per_page: 10,
            page,
            q,
        }
    })
}
export {getSearchList}
